var SnakeHead = SnakeSegment.extend({

	direction: DIRECTION.TOP,
	lastDirection: null,
		
	constructor: function(x, y)
	{
		this.base(x, y);
	},

	draw: function()
	{
		var realSize = SnakeSegment.SIZE * 0.85;
		var offset = (SnakeSegment.SIZE - realSize) * 0.5;
		g_context.fillStyle = '#5CDE5C';
		g_context.strokeStyle = SnakeSegment.BORDER_COLOR;
		g_context.fillRect(this.x + offset, this.y + offset, realSize, realSize);
		g_context.strokeRect(this.x + offset, this.y + offset, realSize, realSize);
	},
	
	setDirection: function(newDirection)
	{
		if (this.isNewDirectionPossible(newDirection))
		{
			this.direction = newDirection;
		}
	},
	
	isNewDirectionPossible: function(newDirection)
	{
		return !(
				(this.lastDirection == DIRECTION.LEFT)   && (newDirection == DIRECTION.RIGHT)  ||
				(this.lastDirection == DIRECTION.RIGHT)  && (newDirection == DIRECTION.LEFT)   || 
				(this.lastDirection == DIRECTION.TOP)    && (newDirection == DIRECTION.BOTTOM) ||
				(this.lastDirection == DIRECTION.BOTTOM) && (newDirection == DIRECTION.TOP)    ||
				(this.lastDirection == newDirection)
		);
	},
	
	move: function(coords)
	{
		this.moveTo(coords.x, coords.y);
		this.lastDirection = this.direction;
	},
	
	getNewCoords: function()
	{
		var newX = this.x;
		var newY = this.y;
		var offset = SnakeSegment.SIZE;
		switch (this.direction)
		{
		case DIRECTION.TOP:
			newY -= offset;
			break;
		case DIRECTION.BOTTOM:
			newY += offset;
			break;
		case DIRECTION.LEFT:
			newX -= offset;
			break;
		case DIRECTION.RIGHT:
			newX += offset;
			break;
		}
		return new Point(newX, newY);
	}
	
});